package com.hyh.cart.controller;


import com.hyh.cart.domain.Cart;
import com.hyh.cart.result.PageResult;
import com.hyh.cart.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/cart")
public class CartController {

    @Autowired
    private CartService cartService;

    /*
     * @description: 添加商品信息到购物车
     * @param:
     * @return
     * @author
     * @date: 2024/3/21 14:06
     */
    @PostMapping("/add")
    public PageResult addCart(@RequestBody Cart cart) {
        return cartService.addCart(cart);
    }


    /**
     * @description: 商品数量加一
     * @param:
     * @return:
     * @author
     * @date: 2024/3/21 14:22
     */


    @PutMapping ("/addOne/{id}")
    public PageResult addOne(@PathVariable("id") Long id) {
        return cartService.addOne(id);
    }




    /**
     * @description null
     * @param  id
     * @return  PageResult
     * @author hyh
     * @date  2024/4/13 10:02
     */
    @PutMapping("/subOne/{id}")
    public PageResult subOne(@PathVariable("id") Long id) {
        return cartService.subOne(id);
    }



    /*
     * @description: 计算总价
     * @param:  
     * @return:  
     * @author 
     * @date: 2024/3/21 14:51
     */
    @PutMapping("/totalPrice/{id}")
    public PageResult totalPrice(@PathVariable("id") Long id) {
        return cartService.totalPrice(id);
    }


    /*
     * @description: 查询自己的购物车商品
     * @param:
     * @return:
     * @author
     * @date: 2024/3/21 15:11
     */
    @GetMapping("/list/{userId}")
    public PageResult list(@PathVariable("userId") Long userId) {
        return cartService.list(userId);
    }

    /*
     * @description: 清空购物车
     * @param:
     * @return:
     * @author
     * @date: 2024/3/21 15:27
     */
    @DeleteMapping("/delete/{userId}")
    public PageResult delete(@PathVariable("userId") Long userId) {
        return cartService.delete(userId);
    }


    /*
     * @description: 删除购物车中的某个商品
     * @param:
     * @return:
     * @author
     * @date: 2024/3/21 15:30
     */
    @DeleteMapping("/deleteOne/{id}")
    public PageResult deleteOne(@PathVariable("id") Long id) {
        return cartService.deleteOne(id);
    }


    /*
     * @description: 根据id查询购物车情况
     * @param:
     * @return:
     * @author
     * @date: 2024/3/21 18:30
     */
    @GetMapping("/getCart/{id}")
    public Cart getCart(@PathVariable("id") Long id) {
        return cartService.getCart(id);
    }


}
